﻿
using LNet;
using OestsCommon.Model;
using System;
using System.Net.Sockets;
using Utils;
using Utils.signal.impl;

/// <summary>
/// 用来跟客户端做通信 
/// </summary>
namespace OestsServer.Net
{
    public class OESPClientChannel : ClientChannel
    {
        public ProjectType ProjectType = ProjectType.None;
        public OESPClientChannel(){}

        public OESPClientChannel(string listenerName, Socket socket, ClientManager mng) : base(listenerName, socket, mng)
        {
        }

        public override bool CheckUserIsExist(int userDbId)
        {
            return Manager.CheckUserIsExist(userDbId);
        }

        public override void ExceptionHandler(Exception e)
        {
            LogNetDebug.LogError("平台系统处理数据异常:" + e.Message);
        }
        protected override void Recevie(Request request)
        {
            ServerController.Instance.OESPServerListener.Parse(this, request);
        }

        #region 广播消息
        public static Signal<Response> BrocastToTeacher = new Signal<Response>();

        public override void SignalAddListener()
        {
            base.SignalAddListener();
            BrocastToTeacher.AddListener(SendMsgToTeacher);
        }

        private void SendMsgToTeacher(Response response)
        {
            if (User != null)
            {
                if (User.Type == UserType.Teacher)
                {
                    Send(response);
                }
            }
        }

        public override void SignalRemoveListener()
        {
            base.SignalRemoveListener();
            BrocastToTeacher.RemoveListener(SendMsgToTeacher);
        }
        #endregion
    }
}
